package cn.edu.scau.cmi.hombio.web.rest;

import cn.edu.scau.cmi.hombio.dao.EmployeeDAO;
import cn.edu.scau.cmi.hombio.dao.FodderTakeDAO;
import cn.edu.scau.cmi.hombio.dao.FodderTypeDAO;
import cn.edu.scau.cmi.hombio.dao.TaskDAO;

import cn.edu.scau.cmi.hombio.domain.Employee;
import cn.edu.scau.cmi.hombio.domain.FodderTake;
import cn.edu.scau.cmi.hombio.domain.FodderType;
import cn.edu.scau.cmi.hombio.domain.Task;

import cn.edu.scau.cmi.hombio.service.FodderTakeService;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.WebDataBinder;

import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Spring Rest controller that handles CRUD requests for FodderTake entities
 * 
 */

@Controller("FodderTakeRestController")

public class FodderTakeRestController {

	/**
	 * DAO injected by Spring that manages Employee entities
	 * 
	 */
	@Autowired
	private EmployeeDAO employeeDAO;

	/**
	 * DAO injected by Spring that manages FodderTake entities
	 * 
	 */
	@Autowired
	private FodderTakeDAO fodderTakeDAO;

	/**
	 * DAO injected by Spring that manages FodderType entities
	 * 
	 */
	@Autowired
	private FodderTypeDAO fodderTypeDAO;

	/**
	 * DAO injected by Spring that manages Task entities
	 * 
	 */
	@Autowired
	private TaskDAO taskDAO;

	/**
	 * Service injected by Spring that provides CRUD operations for FodderTake entities
	 * 
	 */
	@Autowired
	private FodderTakeService fodderTakeService;

	/**
	 * Select an existing FodderTake entity
	 * 
	 */
	@RequestMapping(value = "/FodderTake/{foddertake_id}", method = RequestMethod.GET)
	@ResponseBody
	public FodderTake loadFodderTake(@PathVariable Integer foddertake_id) {
		return fodderTakeDAO.findFodderTakeByPrimaryKey(foddertake_id);
	}

	/**
	* View an existing Employee entity
	* 
	*/
	@RequestMapping(value = "/FodderTake/{foddertake_id}/employeeByWarehousekepperId/{employee_id}", method = RequestMethod.GET)
	@ResponseBody
	public Employee loadFodderTakeEmployeeByWarehousekepperId(@PathVariable Integer foddertake_id, @PathVariable Integer related_employeebywarehousekepperid_id) {
		Employee employee = employeeDAO.findEmployeeByPrimaryKey(related_employeebywarehousekepperid_id, -1, -1);

		return employee;
	}

	/**
	* Delete an existing Employee entity
	* 
	*/
	@RequestMapping(value = "/FodderTake/{foddertake_id}/employeeByEmployeeId/{employee_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteFodderTakeEmployeeByEmployeeId(@PathVariable Integer foddertake_id, @PathVariable Integer related_employeebyemployeeid_id) {
		fodderTakeService.deleteFodderTakeEmployeeByEmployeeId(foddertake_id, related_employeebyemployeeid_id);
	}

	/**
	* View an existing Employee entity
	* 
	*/
	@RequestMapping(value = "/FodderTake/{foddertake_id}/employeeByEmployeeId/{employee_id}", method = RequestMethod.GET)
	@ResponseBody
	public Employee loadFodderTakeEmployeeByEmployeeId(@PathVariable Integer foddertake_id, @PathVariable Integer related_employeebyemployeeid_id) {
		Employee employee = employeeDAO.findEmployeeByPrimaryKey(related_employeebyemployeeid_id, -1, -1);

		return employee;
	}

	/**
	* Create a new FodderType entity
	* 
	*/
	@RequestMapping(value = "/FodderTake/{foddertake_id}/fodderType", method = RequestMethod.POST)
	@ResponseBody
	public FodderType newFodderTakeFodderType(@PathVariable Integer foddertake_id, @RequestBody FodderType foddertype) {
		fodderTakeService.saveFodderTakeFodderType(foddertake_id, foddertype);
		return fodderTypeDAO.findFodderTypeByPrimaryKey(foddertype.getId());
	}

	/**
	* Get FodderType entity by FodderTake
	* 
	*/
	@RequestMapping(value = "/FodderTake/{foddertake_id}/fodderType", method = RequestMethod.GET)
	@ResponseBody
	public FodderType getFodderTakeFodderType(@PathVariable Integer foddertake_id) {
		return fodderTakeDAO.findFodderTakeByPrimaryKey(foddertake_id).getFodderType();
	}

	/**
	* Create a new FodderTake entity
	* 
	*/
	@RequestMapping(value = "/FodderTake", method = RequestMethod.POST)
	@ResponseBody
	public FodderTake newFodderTake(@RequestBody FodderTake foddertake) {
		fodderTakeService.saveFodderTake(foddertake);
		return fodderTakeDAO.findFodderTakeByPrimaryKey(foddertake.getId());
	}

	/**
	* Delete an existing FodderTake entity
	* 
	*/
	@RequestMapping(value = "/FodderTake/{foddertake_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteFodderTake(@PathVariable Integer foddertake_id) {
		FodderTake foddertake = fodderTakeDAO.findFodderTakeByPrimaryKey(foddertake_id);
		fodderTakeService.deleteFodderTake(foddertake);
	}

	/**
	* Register custom, context-specific property editors
	* 
	*/
	@InitBinder
	public void initBinder(WebDataBinder binder, HttpServletRequest request) { // Register static property editors.
		binder.registerCustomEditor(java.util.Calendar.class, new org.skyway.spring.util.databinding.CustomCalendarEditor());
		binder.registerCustomEditor(byte[].class, new org.springframework.web.multipart.support.ByteArrayMultipartFileEditor());
		binder.registerCustomEditor(boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(false));
		binder.registerCustomEditor(Boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(true));
		binder.registerCustomEditor(java.math.BigDecimal.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(java.math.BigDecimal.class, true));
		binder.registerCustomEditor(Integer.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Integer.class, true));
		binder.registerCustomEditor(java.util.Date.class, new org.skyway.spring.util.databinding.CustomDateEditor());
		binder.registerCustomEditor(String.class, new org.skyway.spring.util.databinding.StringEditor());
		binder.registerCustomEditor(Long.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Long.class, true));
		binder.registerCustomEditor(Double.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Double.class, true));
	}

	/**
	* Save an existing Employee entity
	* 
	*/
	@RequestMapping(value = "/FodderTake/{foddertake_id}/employeeByEmployeeId", method = RequestMethod.PUT)
	@ResponseBody
	public Employee saveFodderTakeEmployeeByEmployeeId(@PathVariable Integer foddertake_id, @RequestBody Employee employeebyemployeeid) {
		fodderTakeService.saveFodderTakeEmployeeByEmployeeId(foddertake_id, employeebyemployeeid);
		return employeeDAO.findEmployeeByPrimaryKey(employeebyemployeeid.getId());
	}

	/**
	* View an existing Task entity
	* 
	*/
	@RequestMapping(value = "/FodderTake/{foddertake_id}/task/{task_id}", method = RequestMethod.GET)
	@ResponseBody
	public Task loadFodderTakeTask(@PathVariable Integer foddertake_id, @PathVariable Integer related_task_id) {
		Task task = taskDAO.findTaskByPrimaryKey(related_task_id, -1, -1);

		return task;
	}

	/**
	* Get Employee entity by FodderTake
	* 
	*/
	@RequestMapping(value = "/FodderTake/{foddertake_id}/employeeByEmployeeId", method = RequestMethod.GET)
	@ResponseBody
	public Employee getFodderTakeEmployeeByEmployeeId(@PathVariable Integer foddertake_id) {
		return fodderTakeDAO.findFodderTakeByPrimaryKey(foddertake_id).getEmployeeByEmployeeId();
	}

	/**
	* Get Task entity by FodderTake
	* 
	*/
	@RequestMapping(value = "/FodderTake/{foddertake_id}/task", method = RequestMethod.GET)
	@ResponseBody
	public Task getFodderTakeTask(@PathVariable Integer foddertake_id) {
		return fodderTakeDAO.findFodderTakeByPrimaryKey(foddertake_id).getTask();
	}

	/**
	* Save an existing FodderType entity
	* 
	*/
	@RequestMapping(value = "/FodderTake/{foddertake_id}/fodderType", method = RequestMethod.PUT)
	@ResponseBody
	public FodderType saveFodderTakeFodderType(@PathVariable Integer foddertake_id, @RequestBody FodderType foddertype) {
		fodderTakeService.saveFodderTakeFodderType(foddertake_id, foddertype);
		return fodderTypeDAO.findFodderTypeByPrimaryKey(foddertype.getId());
	}

	/**
	* Save an existing Task entity
	* 
	*/
	@RequestMapping(value = "/FodderTake/{foddertake_id}/task", method = RequestMethod.PUT)
	@ResponseBody
	public Task saveFodderTakeTask(@PathVariable Integer foddertake_id, @RequestBody Task task) {
		fodderTakeService.saveFodderTakeTask(foddertake_id, task);
		return taskDAO.findTaskByPrimaryKey(task.getId());
	}

	/**
	* Create a new Employee entity
	* 
	*/
	@RequestMapping(value = "/FodderTake/{foddertake_id}/employeeByWarehousekepperId", method = RequestMethod.POST)
	@ResponseBody
	public Employee newFodderTakeEmployeeByWarehousekepperId(@PathVariable Integer foddertake_id, @RequestBody Employee employee) {
		fodderTakeService.saveFodderTakeEmployeeByWarehousekepperId(foddertake_id, employee);
		return employeeDAO.findEmployeeByPrimaryKey(employee.getId());
	}

	/**
	* Save an existing Employee entity
	* 
	*/
	@RequestMapping(value = "/FodderTake/{foddertake_id}/employeeByWarehousekepperId", method = RequestMethod.PUT)
	@ResponseBody
	public Employee saveFodderTakeEmployeeByWarehousekepperId(@PathVariable Integer foddertake_id, @RequestBody Employee employeebywarehousekepperid) {
		fodderTakeService.saveFodderTakeEmployeeByWarehousekepperId(foddertake_id, employeebywarehousekepperid);
		return employeeDAO.findEmployeeByPrimaryKey(employeebywarehousekepperid.getId());
	}

	/**
	* Create a new Employee entity
	* 
	*/
	@RequestMapping(value = "/FodderTake/{foddertake_id}/employeeByEmployeeId", method = RequestMethod.POST)
	@ResponseBody
	public Employee newFodderTakeEmployeeByEmployeeId(@PathVariable Integer foddertake_id, @RequestBody Employee employee) {
		fodderTakeService.saveFodderTakeEmployeeByEmployeeId(foddertake_id, employee);
		return employeeDAO.findEmployeeByPrimaryKey(employee.getId());
	}

	/**
	* Create a new Task entity
	* 
	*/
	@RequestMapping(value = "/FodderTake/{foddertake_id}/task", method = RequestMethod.POST)
	@ResponseBody
	public Task newFodderTakeTask(@PathVariable Integer foddertake_id, @RequestBody Task task) {
		fodderTakeService.saveFodderTakeTask(foddertake_id, task);
		return taskDAO.findTaskByPrimaryKey(task.getId());
	}

	/**
	* Delete an existing Employee entity
	* 
	*/
	@RequestMapping(value = "/FodderTake/{foddertake_id}/employeeByWarehousekepperId/{employee_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteFodderTakeEmployeeByWarehousekepperId(@PathVariable Integer foddertake_id, @PathVariable Integer related_employeebywarehousekepperid_id) {
		fodderTakeService.deleteFodderTakeEmployeeByWarehousekepperId(foddertake_id, related_employeebywarehousekepperid_id);
	}

	/**
	* Delete an existing FodderType entity
	* 
	*/
	@RequestMapping(value = "/FodderTake/{foddertake_id}/fodderType/{foddertype_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteFodderTakeFodderType(@PathVariable Integer foddertake_id, @PathVariable Integer related_foddertype_id) {
		fodderTakeService.deleteFodderTakeFodderType(foddertake_id, related_foddertype_id);
	}

	/**
	* Save an existing FodderTake entity
	* 
	*/
	@RequestMapping(value = "/FodderTake", method = RequestMethod.PUT)
	@ResponseBody
	public FodderTake saveFodderTake(@RequestBody FodderTake foddertake) {
		fodderTakeService.saveFodderTake(foddertake);
		return fodderTakeDAO.findFodderTakeByPrimaryKey(foddertake.getId());
	}

	/**
	* Show all FodderTake entities
	* 
	*/
	@RequestMapping(value = "/FodderTake", method = RequestMethod.GET)
	@ResponseBody
	public List<FodderTake> listFodderTakes() {
		return new java.util.ArrayList<FodderTake>(fodderTakeService.loadFodderTakes());
	}

	/**
	* Get Employee entity by FodderTake
	* 
	*/
	@RequestMapping(value = "/FodderTake/{foddertake_id}/employeeByWarehousekepperId", method = RequestMethod.GET)
	@ResponseBody
	public Employee getFodderTakeEmployeeByWarehousekepperId(@PathVariable Integer foddertake_id) {
		return fodderTakeDAO.findFodderTakeByPrimaryKey(foddertake_id).getEmployeeByWarehousekepperId();
	}

	/**
	* View an existing FodderType entity
	* 
	*/
	@RequestMapping(value = "/FodderTake/{foddertake_id}/fodderType/{foddertype_id}", method = RequestMethod.GET)
	@ResponseBody
	public FodderType loadFodderTakeFodderType(@PathVariable Integer foddertake_id, @PathVariable Integer related_foddertype_id) {
		FodderType foddertype = fodderTypeDAO.findFodderTypeByPrimaryKey(related_foddertype_id, -1, -1);

		return foddertype;
	}

	/**
	* Delete an existing Task entity
	* 
	*/
	@RequestMapping(value = "/FodderTake/{foddertake_id}/task/{task_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteFodderTakeTask(@PathVariable Integer foddertake_id, @PathVariable Integer related_task_id) {
		fodderTakeService.deleteFodderTakeTask(foddertake_id, related_task_id);
	}
}